package com.example.toy.core.reader;

import com.example.toy.core.table.ToyTableMeta;
import org.apache.hadoop.fs.Path;

import java.util.Locale;

public class ToyFileReaderFactory {

  public static final String PARQUET_EXTENSION = ".parquet";
  public static final String AVRO_EXTENSION = ".avro";

  public static ToyFileReader build(ToyTableMeta meta, Path path) {
    String name = path.getName().toLowerCase(Locale.ROOT);
    if (name.endsWith(PARQUET_EXTENSION)) {
      return new DefaultToyBaseFileReader(meta, path);
    } else if (name.endsWith(AVRO_EXTENSION)) {
      return new DefaultToyDeltaFileReader(meta, path);
    } else {
      throw new IllegalArgumentException(
          "Can not build ToyFileReader for unknown file extension: " + path);
    }
  }
}
